import { getIndexList, getTargetTypeList } from '../../api/manage'


Component({
  mixins: [],
  data: {
    // 当前页码
    page: 1,
    // 每页条数
    size: 100,
    // 当前展示的指标列表
    targetList: "",
    // 当前搜索的指标名称
    currentSearchIndexName: "",
    // 当前选择的指标分类
    currentSelectIndexLibTypeCode: "",
    // 搜索框关键字
    searchKeyWord: '',
    // 指标类型列表
    targetTypeList: []
  },
  props: {},
  didMount() {
    this.getIndexLibListFunc()
    this.getTargetTypeListFunc()
  },
  didUpdate() { },
  didUnmount() { },
  methods: {
    // 搜索按钮点击事件
    searchClick() {
      this.getIndexLibListFunc()
    },
    // 筛选栏选择Change事件
    filterTypeChange(e) {
      console.log('选择的类型', e);

      if (e == '99999') {
        this.setData({
          currentSelectIndexLibTypeCode: ''
        })
      } else {
        this.setData({
          currentSelectIndexLibTypeCode: e
        })
      }
      this.getIndexLibListFunc()
    },
    // 搜索框输入框change事件
    searchInputChange(e) {
      this.setData({
        currentSearchIndexName: e
      })
      // 如果为空字符串,则触发请求
      if (e == '') {
        this.getIndexLibListFunc()
      }
    },
    // 查询指标库列表函数
    async getIndexLibListFunc() {
      dd.showLoading({
        content: "加载中"
      })
      let data = {
        page: this.data.page,
        size: this.data.size,
        targetLibTypeCode: this.data.currentSelectIndexLibTypeCode,
        targetLibName: this.data.currentSearchIndexName
      }
      await getIndexList(data).then((res) => {
        console.log('查询指标库列表', res);
        this.setData({
          targetList: res.data.list
        })
        dd.hideLoading()
      }).catch((err) => {
        dd.hideLoading()
      })
    },
    // 查询指标库类型列表的函数
    async getTargetTypeListFunc() {
      let data = {
        typeCode: '007'
      }
      await getTargetTypeList(data).then((res) => {

        let nTargetTypeList = res.data.map((item) => {
          return {
            value: item.dictCode,
            text: item.dictName
          }
        })
        nTargetTypeList.unshift({
          value: "99999",
          text: '全部指标'
        })
        this.setData({
          targetTypeList: nTargetTypeList
        })
        console.log('指标库类型列表', nTargetTypeList);
      })
    }
  },
});
